package com.example.cardgame

import android.app.Activity
import android.os.Bundle
import android.widget.Button
import android.widget.EditText
import androidx.appcompat.app.AppCompatActivity

class EditInfoActivity : AppCompatActivity() {

    private lateinit var edtName: EditText
    private lateinit var edtGender: EditText
    private lateinit var edtPhone: EditText
    private lateinit var btnSave: Button

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_edit_info)

        // 绑定UI组件
        edtName = findViewById(R.id.edt_name)
        edtGender = findViewById(R.id.edt_gender)
        edtPhone = findViewById(R.id.edt_phone)
        btnSave = findViewById(R.id.btn_save)

        // 获取从 MainActivity 传递来的初始信息
        val currentName = intent.getStringExtra("currentName")
        val currentGender = intent.getStringExtra("currentGender")
        val currentPhone = intent.getStringExtra("currentPhone")

        // 设置初始值
        edtName.setText(currentName)
        edtGender.setText(currentGender)
        edtPhone.setText(currentPhone)

        // 保存修改并返回数据
        btnSave.setOnClickListener {
            val resultIntent = intent
            resultIntent.putExtra("newName", edtName.text.toString())
            resultIntent.putExtra("newGender", edtGender.text.toString())
            resultIntent.putExtra("newPhone", edtPhone.text.toString())
            setResult(Activity.RESULT_OK, resultIntent)
            finish()
        }
    }
}
